package com.yingside.gui.review;

import com.lovo.netCRM.component.LovoTree;
import com.lovo.netCRM.component.LovoTreeNode;

import javax.swing.*;
import java.awt.*;

public class MovieMainFrame extends JFrame {

    private LovoTree tree;
    private CardLayout cardLayout;

    private JPanel mainPanel;

    private MoviePanel moviePanel;
    private NovelPanel novelPanel;

    public MovieMainFrame(){

        this.setTitle("管理系统");
        this.setBounds(200,100,600,400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        initCard();
        //树状菜单
        initTree();
    }

    private void initCard() {
        mainPanel = new JPanel();
        cardLayout = new CardLayout();
        moviePanel = new MoviePanel();
        novelPanel = new NovelPanel();
        //mainPanel布局管理是是卡牌布局
        mainPanel.setLayout(cardLayout);

        //放入电影的panel，命名为movie
        mainPanel.add(moviePanel,"movie");
        mainPanel.add(novelPanel,"novel");

        //把mainPanel放入到窗口容器中
        this.add(mainPanel,BorderLayout.CENTER);
    }

    public void initTree(){

        LovoTreeNode root = new LovoTreeNode("2021春节档盘点");
        LovoTreeNode movieNode = new LovoTreeNode("电影管理"){
            @Override
            public void addListener() {
                System.out.println("电影管理节点被选中了");
                cardLayout.show(mainPanel,"movie");
            }
        };
        LovoTreeNode novelNode = new LovoTreeNode("小说管理"){
            @Override
            public void addListener() {
                System.out.println("小说管理节点被选中了");
                cardLayout.show(mainPanel,"novel");
            }
        };

        root.add(movieNode);
        root.add(novelNode);

        tree = new LovoTree(root);

        this.add(tree, BorderLayout.WEST);
    }

    public static void main(String[] args) {
        MovieMainFrame mmf = new MovieMainFrame();
        mmf.setVisible(true);
    }
}
